mod api;
mod appsettings;

use ::tracing::*;
use appsettings::*;
use away_db::model::appstate::AppState;
use sea_orm::Database;

#[tokio::main]
async fn main() {
    appsettings::init();
    let db_url = config::db_url();
    let host: String = config::host();

    let db = Database::connect(db_url).await.unwrap();

    let appstate = AppState { db: db.clone() };
    api::backgroup_service(db.clone());
    api::http_server(host, appstate);

    match tokio::signal::ctrl_c().await {
        Ok(()) => {
            info!("shutdown");
        }
        Err(err) => {
            info!("Unable to listen for shutdown signal: {}", err);
        }
    }
}
